package com.etoak.controller;

import com.etoak.common.utils.uuid.IdUtils;
import com.etoak.entity.ApplySituation;
import com.etoak.service.IApplySituationService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * Checklist库应用场景controller
 *
 * @author zhixuebin
 * @date 2022-05-12
 */
@RestController
@RequestMapping("/goertek/checklist/applySituation")
public class ApplySituationController extends BaseController {

    @Autowired
    IApplySituationService applySituationService;

    /**
     * 添加应用场景
     * @param applySituation
     * @return
     */
    @PostMapping("/add")
    public AjaxResult addApplySituation(@RequestBody ApplySituation applySituation){
        //验重
        List<ApplySituation> search = applySituationService.getApplySituation(applySituation);

        if(StringUtils.isNull(search) || search.size() < 1){
            //设置主键
            String id = IdUtils.simpleUUID();
            applySituation.setId(id);
            applySituationService.add(applySituation);
        }else{
            return AjaxResult.error("应用场景已存在！");
        }
        return AjaxResult.success("添加成功");
    }

    /**
     * 查询应用场景
     * @param applySituation
     * @return
     */
    @GetMapping("/getApplySituation")
    public AjaxResult getApplySituationByProductLine(ApplySituation applySituation){
        List<ApplySituation> applySituationList = applySituationService.getApplySituation(applySituation);
        return AjaxResult.success(applySituationList);
    }

}
